<template>
  <div class="app-container">
    <upload-excel
      :on-success="handleSuccess"
      :before-upload="beforeUpload"
    />
    <el-table
      :data="tableData"
      border
      style="width: 100%;margin-top:20px;"
    >
      <el-table-column
        v-for="item of tableHeader"
        :key="item"
        :prop="item"
        :label="item"
      />
    </el-table>
  </div>
</template>

<script lang="ts" setup>
import { ZHTOEN } from '@/utils/ZHTOEN'
import { importEmployee } from '@/api/employees'
import router from '@/router'
function beforeUpload(file:File) {
  //console.log('file',file)
  // 1m大小
  const isLt1M = file.size / 1024 / 1024 < 1
  if (isLt1M) {
    return true
  }
  ElMessage({
    message: 'Please do not upload files larger than 1m in size.',
    type: 'warning',
  })
  return false
}
const tableData=ref()
const tableHeader=ref()
function  handleSuccess({ results,header }:TsModel1) {
  console.log('data',JSON.stringify(results))
  
  //表格数据
  tableData.value = results
  // 表头
  tableHeader.value = header
  const res=ZHTOEN(results)
  loadImportEmployee(res)
 
  console.log('results',res)
  console.log('header',header)
  router.back()
  // 批量导入数据
  //this.loadExcelEmployee(this.formatDate(results))
}
const loadImportEmployee =async(data:ExcelData[]) => {
  try {
    const res = await importEmployee(data)
    console.log('importEmployee',res)
  } catch (error) {
    console.log(error)
  }
}

</script>
